*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Table A2
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************


cd "~/Dropbox/ReclassificationRisk/"
use database_individual_level.dta, replace 


**************************************************************************************************
** BEGINING OF USIC ESTIMATES
** TWO STEP REGRESSION USING THIS SAMPLE (ROBUSTNESS ON LEAVING THE SAMPLE) **
**************************************************************************************************
tsset mbr_sys_id year
egen stderrorscluster = group(customer_number year)
gen SEX = (gdr_cd=="F")
gen industry = substr(sic_cd,1,1)
tab industry, gen(industy_dummy)
**************************************************************************************************
local conditions "lagged_code_hypertension lagged_code_heartfailure lagged_chronic_ami laggeed_code_respfailure  lagged_code_brainhemorr lagged_chronic_cancer lagged_chronic_diabetes lagged_code_asthma" 
mkspline reg16 1 reg17 = mean_pred_riskscore_rp 
*if year==2015 /*making the spline on the delta for 2015, cross section estimate */
*gen reg1 =  mean_pred_riskscore_rp 
gen reg2 = laggedscore 
gen reg3 = age 
gen reg4 = SEX
gen reg5 = industy_dummy1
gen reg6 = industy_dummy2
gen reg7 = industy_dummy3
gen reg8 = industy_dummy4 
gen reg9 = industy_dummy5
gen reg10 = industy_dummy6
gen reg11 = industy_dummy7
gen reg12 = industy_dummy8
gen reg13 = industy_dummy9
gen reg14 = industy_dummy10
gen reg15 = numpeople
probit exit_new reg* if year==2014, cluster(stderrorscluster) noconstant
forvalues i=2/17 {
scalar coeffprobit`i' = _b[reg`i']
}
*probit exit_new laggedscore mean_pred_riskscore_rp age SEX industy_dummy* numpeople if year==2014, cluster(stderrorscluster) noconstant
local n_probit = e(N)
matrix V = e(V)* `n_probit'
*ivprobit exit_new (laggedscore mean_pred_riskscore_rp = laggedscore_ORS mean_ORS_riskscore_rp) age SEX industy_dummy* numpeople if year==2014, cluster(stderrorscluster) 
margins, dydx(*)
predict linear_index, xb
gen prob_leaving = normal(linear_index)
gen prob_leaving2 = prob_leaving^2
gen prob_leaving3 = prob_leaving^3
gen prob_leaving4 = prob_leaving^4
gen prob_leaving5 = prob_leaving^5
gen prob_leaving6 = prob_leaving^6 
tsset mbr_sys_id year
***** *****

*newjoiners2013_stayers2015 -> People with complete observations in 2014 and 2015

set more off
**************************************************************************************************
** PANEL A: Fixed effects estimates 
**************************************************************************************************
*reghdfe mean_premium yeardum* (mean_pred_riskscore_rp = mean_ORS_riskscore_rp), absorb(mbr_sys_id) vce(cluster customer_number year)
reghdfe mean_premium mean_pred_riskscore_rp  yeardum* if  newjoiners2013_stayers2015 == 1, absorb(mbr_sys_id) vce(cluster customer_number year)
gen sample = e(sample)
eststo mod1  
reghdfe mean_premium mean_pred_riskscore_rp prob_leaving yeardum* if newjoiners2013_stayers2015 == 1, absorb(mbr_sys_id) vce(cluster customer_number year)
eststo mod2
reghdfe mean_premium mean_pred_riskscore_rp prob_leaving* yeardum* if newjoiners2013_stayers2015 == 1 , absorb(mbr_sys_id) vce(cluster customer_number year)
eststo mod3


****************************************************************************************************************** fragment
*********TABLE PANEL A 
esttab mod1 mod2 mod3 using Restat_TableA2.tex , replace label   nonotes nonumbers stats(N, fmt(%12.0fc)) compress cells(b(star fmt(%12.0fc  ) label(" ")) se(fmt( %12.0fc ) label(" ") par) ) collabels(none) nogaps  ///
		title(Main Estimates) mtitles("I" "II" "III" ) ///
		star(* 0.10 ** 0.05 *** 0.01)  ///
		keep( mean_pred_riskscore_rp ) ///
		prefoot( \hline  "Year FE & Yes & Yes & Yes" \\ ///
		"Polynomial Order & No  & First & Sixth" \\ ///
		"Observations & 2013 & 2013 & 2013 & 2013 "\\ \hline) 
eststo clear
*********************************************************************************************


 
*exit 

set more off


**************************************************************************************************
** PANEL B: No Fixed effects estimates 
**************************************************************************************************
reghdfe  mean_premium mean_pred_riskscore_rp  marketdum* yeardum* if sample==1 & newjoiners2013_stayers2015 == 1,  noabsorb vce(cluster customer_number )
eststo mod1  
*regress  mean_premium mean_pred_riskscore_rp  marketdum* prob_leaving yeardum* , cl(customer_number)
reghdfe  mean_premium mean_pred_riskscore_rp  marketdum* prob_leaving yeardum* if sample==1 &  newjoiners2013_stayers2015 == 1 ,  noabsorb vce(cluster customer_number )
eststo mod2
*regress  mean_premium mean_pred_riskscore_rp   marketdum* prob_leaving* yeardum* , cl(customer_number)
reghdfe  mean_premium mean_pred_riskscore_rp  marketdum* prob_leaving* yeardum* if sample==1 &  newjoiners2013_stayers2015 == 1,  noabsorb vce(cluster customer_number year)
eststo mod3

****************************************************************************************************************** fragment
*********TABLE PANEL B
esttab mod1 mod2 mod3 using Restat_TableA2_panelb.tex , replace label   nonotes nonumbers stats(N, fmt(%12.0fc)) compress cells(b(star fmt(%12.0fc  ) label(" ")) se(fmt( %12.0fc ) label(" ") par) ) collabels(none) nogaps  ///
		title(Main Estimates) mtitles("I" "II" "III" ) ///
		star(* 0.10 ** 0.05 *** 0.01)  ///
		keep( mean_pred_riskscore_rp ) ///
		prefoot( \hline  "Year FE & Yes & Yes & Yes" \\ ///
		"Polynomial Order & No  & First & Sixth" \\ ///
		"Observations & 2013 & 2013 & 2013 & 2013 "\\ \hline) 
eststo clear
*********************************************************************************************

exit 

